﻿Public Class frmDanhSachHocSinh_Lop
    Private TenLop As String = ""
    Public Sub New(ByVal _tenlop As String)
        InitializeComponent()
        TenLop = _tenlop
    End Sub
    Private Sub ThêmToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThêmToolStripMenuItem.Click
        Dim frm As frmThemHocSinh_Lop = New frmThemHocSinh_Lop
        frm.Show()
    End Sub

    Private Sub XóaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XóaToolStripMenuItem.Click
        Dim dr As DialogResult = New DialogResult
        dr = MessageBox.Show("Bạn muốn xóa?", "Delete!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)

        If dr = DialogResult.Yes Then
            'Xu ly xoa
        End If

    End Sub

    Private Sub SửaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SửaToolStripMenuItem.Click
        Dim hs As DTOHocSinh = New DTOHocSinh
        Try

            If dtgvDSHS.CurrentRow.Cells("MaHS").Value <> "" Then
                Dim frm As frmThemHocSinh = New frmThemHocSinh(hs)
                frm.ShowDialog()
            Else
                MessageBox.Show("Bạn chưa chọn giá trị.")
                Return
            End If

        Catch ex As Exception
            MessageBox.Show("Lỗi.")
            Return
        End Try

    End Sub

    Public Sub LoadAllData()
        Dim strQuery As String = "Select * from HocSinh where TenLop='" + TenLop + "'"
        Dim hs As DAOHocSinh = New DAOHocSinh
        Dim table As DataTable = New DataTable
        table = hs.LoadTable(strQuery, Application.StartupPath + "\database\database.mdb")
        dtgvDSHS.AutoGenerateColumns = False
        dtgvDSHS.DataSource = table
    End Sub
    Private Sub frmDanhSachHocSinh_Lop_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "Danh sách học sinh lớp " + TenLop

        If TenLop <> "" Then
            LoadAllData()
        End If
    End Sub
End Class